package springboot.springMVC.controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/login")
    public Boolean login(String username, String password, HttpSession session) {
//        if(username==null || password==null)
//            return false;
        if(StringUtils.hasLength(username)||StringUtils.hasLength(password)){}
//        if(username.equals("admin") && password.equals("123456")) {
//            return true;
//        }
        if("admin".equals(username) && "123456".equals(password)) {
            session.setAttribute("username", username);
            //session.setAttribute("password", password);
            return true;
        }
        return false;
    }

    @RequestMapping("/getLoginUser")
    public String getLoginUser(HttpSession session) {
        String username = (String) session.getAttribute("username");
        return username;
    }
}
